app.service('homeService',['$http','$q','utilService',function($http,$q,utilService){
    var _this_=this;

    //查询订单曲线图
    _this_.queryHomeHeader= function ($scope) {
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'home/header'
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        })

        return deferred.promise;
    }

    //查询订单曲线图
    _this_.queryOrdersInfo= function ($scope) {
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'home/orders',
            params:{year:$scope.ordersYears,'month':$scope.ordersMonth}
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        })

        return deferred.promise;
    }

    //
    _this_.queryForGoods= function ($scope) {
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'home/goods',
            params:{'month':$scope.goodsMonth}
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        })

        return deferred.promise;
    }


    _this_.queryInternalNotice= function ($scope) {
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'home/shop/notice'
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        })

        return deferred.promise;
    }

    //查询店铺信息
    _this_.queryShop= function ($scope) {
        var deferred = $q.defer();

        utilService.get({
            url:$scope.app.domain + 'shop/session'
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        })

        return deferred.promise;
    }

    //查询所有的未读消息
    _this_.queryUnread = function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'notice/unread',
            params:$scope.noticeRead
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        })

        return deferred.promise;
    }

    //确认消息
    _this_.confirmNotice = function ($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'notice/confirm',
            data:$scope.confirm,
            method:'PUT'
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("连接服务器出错！");
        })
        return deferred.promise;
    }

}])